#分数背包
goods=[(60,10),(100,20),(120,30)]#每个商品元组表示(价格，重量)
goods.sort(key=lambda x:x[0]/x[1] , reverse=True)#价格/重量

def fractional_backpack(goods,w):
    m=[0 for _ in range(len(goods))]
    total_v=0
    for i,(prize,weight) in enumerate(goods):
        if w>weight:
            m[i]=1
            w-=weight
            total_v+=prize
        else:
            m[i]=w/weight
            w=0
            total_v+=m[i]*prize
            break
    return  total_v, m

print(fractional_backpack(goods,50))